<?php

namespace App\Http\Middleware;

use App\Exceptions\ApiException;
use App\Models\User;
use Closure;
use Dingo\Api\Routing\Helpers;

class CheckLoginStatus
{
    use Helpers;

    /**
     * @param $request
     * @param Closure $next
     * @return mixed
     * @throws ApiException
     */
    public function handle($request, Closure $next)
    {
        if ($this->user->login_status == User::FORBIDDEN) {
            throw new ApiException(trans('api.operation_rejected'), 403);
        }

        return $next($request);
    }
}
